<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;

class YfsdkApiCheck
{
    // 研发调用-允许访问的域名列表
    protected $domainList = [
        'yfsdk-server.waibaook.com',
    ];

    // 研发调用-允许访问的路由
    protected $roleList = [
        '/api/yfsdk/user/firstup',
        '/api/yfsdk/user/login',
        '/api/yfsdk/pay/create',
        '/api/yfsdk/role/reg',
        '/api/yfsdk/role/login',
        '/api/yfsdk/role/xuni_pay',
    ];

    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse)  $next
     * @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
     */
    public function handle(Request $request, Closure $next)
    {
        $uri = $request->getPathInfo();
        if (in_array($request->getHost(), $this->domainList)) {
            if (!in_array($uri, $this->roleList)) {
                abort(403, 'Forbidden');
            }
        }

        return $next($request);
    }
}
